import { _decorator, Component, Node, EditBoxComponent, director } from "cc";
import { Tooltip } from "../../prefabs/Tooltip";
import request from "../../utils/request";
const { ccclass, property } = _decorator;

@ccclass("Home/Register")
export class Register extends Component {
    @property(Node)
    private userName: Node = null;

    @property(Node)
    private nickName: Node = null;

    @property(Node)
    private password: Node = null;

    @property(Node)
    private tooltip: Node = null;

    handleClose() {
        this.node.active = false;
    }

    handleRegister() {
        const userName = this.userName.getComponent(EditBoxComponent).string;
        const nickName = this.nickName.getComponent(EditBoxComponent).string;
        const password = this.password.getComponent(EditBoxComponent).string;
        request.post("/users/register", { userName, nickName, password }).then(({ code, message, token }) => {
            this.tooltip.getComponent(Tooltip).show(message);
            setTimeout(() => {
                this.handleClose();
            }, 2000);
        });
    }
}
